import { dictionaryList } from '@/services/dictionary';
import { queryFlowType } from '../services';

export default {
    namespace: 'flowCommon',
    state: {
        flowType: [],
        orderType: '',
        processStatusType: [],
        instStatus: ''
    },

    effects: {
        *fetchProcessStatusType({ payload }, { call, put }) {
            const result = yield call(dictionaryList, payload);

            if (result.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        processStatusType: result.data
                    }
                });
            }
        },
        // 获取流程类型
        *fetchFlowType({ payload }, { call, put }) {
            const response = yield call(queryFlowType, payload);
            if (response.code === 10000) {
                yield put({
                    type: 'save',
                    payload: {
                        flowType: response.data
                    }
                });
            }
        }
    },
    reducers: {
        save(state, { payload }) {
            return {
                ...state,
                ...payload
            };
        }
    }
};
